home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Goodies / AutoGuest / AutoGuest.c < prev    next >
Text File  |  1991-10-16  |  3KB  |  133 lines

  1. /*
  2. //  Glue for the various AutoGuest patches
  3. //
  4. //    by Greg Anderson, Paul Young and Michael Gough
  5. */
  6. #include <Traps.h>
  7. #include <Processes.h>
  8. #include <PPCToolbox.h>
  9.  
  10. #include "AutoGuest.h"
  11.  
  12. /*
  13. // Strangely enough, the PPC Dispatch trap isn't defined in any .h file
  14. */
  15. #define _PPC        0xA0DD
  16.  
  17.  
  18. /*----------------------------------------------------------------------
  19.  
  20.     Install the PPC AutoGuest patch
  21.     
  22.     This patch allows an application to start a session with a
  23.     remote computer without bringing up an authentication dialog
  24.     box if (& only if) it is possible to connect to said machine
  25.     as a guest
  26.     
  27.     This function returns a longword which should be passed to
  28.     DeinstallPPCAutoGuest to remove the patch
  29.     
  30. ----------------------------------------------------------------------*/
  31. long InstallPPCAutoGuest()
  32. {
  33.     extern void PPCAutoGuest();
  34.     extern void OldPPCAddress();
  35.  
  36.     long        oldPPCDispatch;
  37.     long        newPPCDispatch;
  38.     long*        modifyReturnAddress;
  39.     
  40.      oldPPCDispatch = NGetTrapAddress(_PPC, OSTrap) ;
  41.     newPPCDispatch = (long)PPCAutoGuest;
  42.     
  43.      if( oldPPCDispatch == newPPCDispatch )
  44.         return 0;
  45.     
  46.     modifyReturnAddress = (long*) (OldPPCAddress);
  47.     *modifyReturnAddress = oldPPCDispatch;
  48.             
  49.     NSetTrapAddress( newPPCDispatch, _PPC, OSTrap);
  50.     
  51.     return oldPPCDispatch;
  52. }
  53.  
  54. /*----------------------------------------------------------------------
  55.     
  56.     Remove the PPC AutoGuest patch
  57.     
  58.     The parameter should be the longword returned from
  59.     InstallPPCAutoGuest
  60.     
  61. ----------------------------------------------------------------------*/
  62. void DeinstallPPCAutoGuest( long oldPPCDispatch )
  63. {
  64.     if( oldPPCDispatch )
  65.         NSetTrapAddress( oldPPCDispatch, _PPC, OSTrap);
  66. }
  67.  
  68. /*----------------------------------------------------------------------
  69.  
  70.     Install the 'No Interaction Allowed' Patch
  71.     
  72.     This patch prevents the EPPC toolbox from returning a
  73.     'No User Interaction Allowed' error (-610) if your application
  74.     attempts to start a session while it is in the background.
  75.     
  76. ----------------------------------------------------------------------*/
  77. long InstallNoInteractionPatch()
  78. {
  79.     extern void DisposePatch();
  80.     extern void OldDisposeAddress();
  81.  
  82.     long        oldDispose;
  83.     long        newDispose;
  84.     long*        modifyReturnAddress;
  85.     
  86.      oldDispose = NGetTrapAddress(_DisposHandle, OSTrap) ;
  87.     newDispose = (long)DisposePatch;
  88.     
  89.      if( oldDispose == newDispose )
  90.         return 0;
  91.     
  92.     modifyReturnAddress = (long*) (OldDisposeAddress);
  93.     *modifyReturnAddress = oldDispose;
  94.     
  95.     NSetTrapAddress( newDispose, _DisposHandle, OSTrap) ;
  96.     
  97.     return oldDispose;
  98. }
  99.  
  100. /*----------------------------------------------------------------------
  101.     
  102.     Remove the 'No Interaction Allowed' Patch
  103.     
  104.     The parameter should be the longword returned from
  105.     InstallPPCAutoGuest
  106.     
  107. ----------------------------------------------------------------------*/
  108. void DeinstallNoInteractionPatch( long oldDispose )
  109. {
  110.     if( oldDispose )
  111.         NSetTrapAddress( oldDispose, _DisposHandle, OSTrap);
  112. }
  113.  
  114. /*----------------------------------------------------------------------
  115.     
  116.     This function returns 'true' if the current process is in the
  117.     foreground.  It is used by the PPC Autoguest patch.
  118.     
  119. ----------------------------------------------------------------------*/
  120. Boolean InForeGround()
  121. {
  122.     ProcessSerialNumber        currentPSN;
  123.     ProcessSerialNumber        forePSN;
  124.     Boolean                    isFore;
  125.         
  126.     GetCurrentProcess( ¤tPSN );
  127.     GetFrontProcess( &forePSN );
  128.     
  129.     SameProcess( ¤tPSN, &forePSN, &isFore );
  130.     
  131.     return isFore;
  132. }
  133.